﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace exsportance.Silverlight.Forms.Controls
{
    [TemplatePart(Name = CollapsibleGridSplitter.CollapseButtonName, Type = typeof(Button))]
    public class CollapsibleGridSplitter : GridSplitter
    {
        #region const
        internal const string CollapseButtonName = "CollapseButton";
        #endregion

        #region events
        public delegate void CollapseButtonClickEventHandler(object sender);
        public event CollapseButtonClickEventHandler CollapseButtonClickEvent;
        #endregion

        #region members
        internal Button CollapseButton { get; set; }
        #endregion

        public CollapsibleGridSplitter()
        {
            this.DefaultStyleKey = typeof(CollapsibleGridSplitter);
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            CollapseButton = this.GetTemplateChild(CollapseButtonName) as Button;
            if (CollapseButton != null)
                CollapseButton.Click += new RoutedEventHandler(OnCollapseButtonClickEvent);
        }


        void OnCollapseButtonClickEvent(object sender, RoutedEventArgs e)
        {
            //if (RightColumn.Width.Value == 0)
            //{
            //    RightColumn.Width = new GridLength(200);
            //}
            //else if (sender != this)
            //{
            //    RightColumn.Width = new GridLength(0);
            //}

            if (CollapseButtonClickEvent != null)
                CollapseButtonClickEvent(sender);
        }

        //private void Grid_SizeChanged(object sender, SizeChangedEventArgs e)
        //{
        //    if (RightColumn.Width.Value == 0)
        //    {
        //        GridSplitter.CollapseButton.Content = "4";
        //    }
        //    else
        //    {
        //        GridSplitter.CollapseButton.Content = "3";
        //    }
        //}
    }
}
